//
//  MainTabBarBtn.m
//  SinaWeibo-OC
//
//  Created by apple on 15/11/28.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "MainTabBarBtn.h"

@implementation MainTabBarBtn

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        
        [self setUPUI];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUPUI];
    }
    return self;
}

- (void)setUPUI{
    
    //..
    //设置按钮的图片和标题居中
    self.imageView.contentMode =  UIViewContentModeCenter;//维持原来的大小
    
    self.titleLabel.font = [UIFont systemFontOfSize:13];
    
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    //设置选中和默认状态的字体颜色
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [self setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
}
- (CGRect)titleRectForContentRect:(CGRect)contentRect {
#warning 如果对自定义的控件改变transform  那么不能访问控件的self.frame
    CGFloat titleX = 0;
    
    CGFloat titleY = contentRect.size.height * 0.6;
    
    CGFloat titleW = contentRect.size.width;

    CGFloat titleH = contentRect.size.height - self.frame.size.height * 0.6 ;
    
    return CGRectMake(titleX, titleY, titleW, titleH);
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    
    CGFloat imageX = 0;
    
    CGFloat imageY = 0;
    
    CGFloat imageW = contentRect.size.width;
    
    CGFloat imageH = contentRect.size.height * 0.6 ;
    
    return CGRectMake(imageX, imageY, imageW, imageH);
}
- (void)setHighlighted:(BOOL)highlighted {
    
    
}
@end
